%{
#include "p-machine.hh"
#include <stdio.h>
extern int yylex();
extern void yyerror(const char *);
extern FILE *yyin;
%}

%token EOL
%token IF HERE INT LONG THEN

%%

expression:	cond_check actions EOL { printf("\nIs valid!\n"); }

cond_check:	IF bool_exprs THEN { printf(" %04x", pcode_end_on_false); }
bool_exprs:	cond_eq | cond_lt | cond_gt

cond_eq:	value '=' value { printf(" %04x", pcode_cmp_eq); }
cond_lt:	value '<' value { printf(" %04x", pcode_cmp_lt); }
cond_gt:	value '>' value { printf(" %04x", pcode_cmp_gt); }

value:		immediate
		| HERE { printf(" %04x", pcode_load_here); }

immediate:	INT { printf(" %04x%04x", pcode_load_immediate, $1); }

actions:
	| action
	;

action:	LONG { printf(" %04x", pcode_look_long); }

%%

int main(int argc, char **argv) {
  do {
    yyparse();
  } while(!feof(yyin));
  return 0;
}

void yyerror(const char *s) {
  fprintf(stderr, "parse error: %s\n", s);
}
